﻿Public Class TipoProducto 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub TipoProducto_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.tipoproducto' table. You can move, or remove it, as needed.
            Me.TipoproductoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipoproducto)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.tipoproducto' table. You can move, or remove it, as needed.
            Me.TipoproductoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipoproducto)
        Catch ex As Exception
            AlertControl1.Show(Owner, "ERROR", "No se pudo cargar los registros de la Base de Datos")
        End Try
        PanelArriba.Enabled = False
        PanelAbajo.Enabled = True
    End Sub

    Private Sub TipoproductoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TipoproductoBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TipoproductoBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        PanelArriba.Enabled = True
        PanelAbajo.Enabled = False
        Mostrar()
    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()
        PanelArriba.Enabled = True
        PanelAbajo.Enabled = False
    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        TipoproductoTableAdapter.Delete(Val(IdtipoTextBox.Text), DescripcionTextBox.Text)
        Me.TipoproductoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipoproducto)
        Mostrar()
        Mostrar()
    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
        If DescripcionTextBox.Text = "" Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe de ingresar una descripcion de Categoría Item")
        Else
            ErrorProvider1.SetError(DescripcionTextBox, Nothing)
            TipoproductoBindingNavigatorSaveItem.PerformClick()
            Mostrar()
        End If
    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
        Mostrar()
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        Me.TipoproductoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipoproducto)
    End Sub

    Private Sub PanelArriba_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PanelArriba.Paint

    End Sub

    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub
End Class